// custom-tab-bar/index.js
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'

Component({
  options: {
    styleIsolation: 'shared'
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      active: 'activeTabBarIndex',
      token: 'token'
    },
    actions: {
      updateActive: 'updateActiveTabBarIndex'
    },
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    "list": [{
      "pagePath": "/pages/home/home",
      "text": "首页",
      "icon": "wap-home-o"
    }, {
      "pagePath": "/pages/video/video",
      "text": "视频",
      "icon": "tv-o"
    }, {
      "pagePath": "/pages/question/question",
      "text": "问答",
      "icon": "chat-o"
    }, {
      "pagePath": "/pages/user/user",
      "text": "我的",
      "icon": "user-o"
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail });
      this.updateActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },

    handleToken() {
      return store.token ? "我的" : "未登录"
    }
  }
})
